package cn.aylog.controller;

import cn.aylog.pojo.User;
import cn.aylog.service.UserService;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {

    Logger LOG = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;

    @RequestMapping("getById")
    public String getById() {
        LOG.info("日志输出。。。");
        User user = userService.getById(55);
//        return JSONObject.toJSONString(user);
        return user.toJsonString();
    }

    @RequestMapping("/getCount")
    public String getCount() {
        LOG.info("日志输出。。。");
        Integer count = userService.getCount();
        Map<String, Object> map = new HashMap<>();
        map.put("count", count);
        return JSONObject.toJSONString(map);
    }
}
